<%@page import="models.User"%>
<%@include file="template/configuration.jsp" %>
<%@page import="models.Employee"%>
<%@page import="java.util.List"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>${website} || Manage student progress</title>
        ${stylesheet}
        ${jquery}
        ${jsdropdown}
        ${jstooltip}
        ${jscollapse}
        ${multipleFilter}
    </head>
    <body>
        <div class="container">
            <%@include file="template/header.jsp" %>
            <div class="content">
                <h1>Manage student progress</h1>
                <label for="search">Search:</label> <input type="text" style="width:200px;"name="search" id="multiplefilter" value=""/>
            
                <!-- clear //-->
                <div class="clear margin-bottom-10"></div>
                <c:choose>
                    <c:when test="${fn:length(courses)!=0}">
                        <c:forEach items="${courses}" var="course">
                            <div class="bundle">
                                <div class="top">
                                    <div class="left">
                                    </div>
                                    <div class="center">
                                        <h5>${course.name}</h5>
                                    </div>
                                    <div class="right">

                                    </div>
                                </div>
                                <!-- clear //-->
                                <div class="clear"></div>
                                <div class="full-block">    
                                    <c:set var="catid" value="${course.id}" /> 
                                    <%
                                        //hu(mq), cd(mq), mq = manage quizes
                                        HibernateUtil humq = new HibernateUtil();
                                        CourseDao cdmq = new CourseDao(humq.openSession());
                                        HttpSession sessie = request.getSession();
                                        List<Course> courseListMC = null;
                                        if (sessie.getAttribute("userrole").equals("Administrator")) {
                                        
                                            courseListMC = cdmq.findAllByCategory(Long.parseLong(pageContext.getAttribute("catid").toString()),10);
                                        } else {
                                            User user = (User) sessie.getAttribute("user");
                                            courseListMC = cdmq.findAllByTeacherAndCategory(user.getMember_id(), Long.parseLong(pageContext.getAttribute("catid").toString()));
                                        }
                                        request.setAttribute("coursesx", courseListMC);
                                        if (true) {
                                    %>
                                    <div>
                                        <table id="search-table" class="overview">
                                            <thead>
                                                <tr>
                                                    <th>Full name</th>
                                                    <th>Email</th>
                                                    <th class="date">Date added</th>
                                                    <c:if test="${sessionScope.userrole == 'Administrator'}">
                                                    <th class="<c:choose><c:when test="${sessionScope.userrole == 'Administrator'}">manage</c:when><c:otherwise>single-icon</c:otherwise></c:choose>">Manage</th>
                                                    </c:if>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <c:set var="i" value="0"/>
                                                <c:forEach items="${course.student}" var="studentje">
                                                    <c:set var="i" value="${i + 1}"/>
                                                    <tr class="pointer <c:choose><c:when test="${i % 2 == 0}">even</c:when><c:otherwise>odd</c:otherwise></c:choose>">
                                                        <td><a href="${url}HandinViewer/view?studentid=${studentje.id}&courseid=${course.id}" class="hidden"></a>${studentje.firstname} ${studentje.insertion} ${studentje.lastname}</td>
                                                        <td>${studentje.user.email}</td>
                                                        <td>${studentje.user.date}</td>
                                                        <c:if test="${sessionScope.userrole == 'Administrator'}">
                                                        <td>
                                                                <a href="${url}ManageStudent/edit?id=${studentje.id}"><img src="${url}images/edit.png"/></a> 
                                                        </td>
                                                        </c:if>
                                                    </tr>
                                                </c:forEach>
                                            </tbody>
                                        </table>  
                                    </div>
                                    <% } else {%>
                                    <div class="no-yet-message">
                                        There are no students enrolled in this course yet.
                                    </div>
                                    <% }%>
                                </div>
                                <!-- clear //-->
                                <div class="clear margin-bottom-10"></div>
                            </div>
                        </c:forEach>
                    </c:when>
                    <c:otherwise>
                        <div class="full-block">
                            There are no courses at this moment.
                        </div>
                    </c:otherwise>
                </c:choose>
            </div>
            <%@include file="template/footer.jsp" %>
        </div>
    </body>
</html>
